﻿/*
    Copyright 2011 Andrew Sydney
 
    This file is part of Syd.ScheduleControls.

    Syd.ScheduleControls is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Syd.ScheduleControls is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Syd.ScheduleControls.  If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;

namespace CMS_GYM.Interface
{
	/// <summary>
	/// Dialog for adding a new appointment.
	/// </summary>
	public partial class frmThemLichSanCauLong : Form
	{
        public int KhachHangId;
        public int IDKhachHangVangLaiChuaThuTien = 0;
        public int IDKhachHangVangLaiDaThuTien = 0;
        public int IDKhachHangVangLai = 0;
        public string MoTa = string.Empty;

		public frmThemLichSanCauLong()
		{
			InitializeComponent();
            KhachHangId = 0;
		}

        /// <summary>
        /// Gets or sets the appointment title.
        /// </summary>
        /// <value>
        /// The appointment title.
        /// </value>
		public string AppointmentTitle {get{return this.txtTitle.Text;}set{this.txtTitle.Text=value;}}
        /// <summary>
        /// Gets or sets the appointment date end.
        /// </summary>
        /// <value>
        /// The appointment date end.
        /// </value>
		public DateTime AppointmentDateEnd {get{return this.dtpDateEnd.Value;}set{this.dtpDateEnd.Value=value;}}
        /// <summary>
        /// Gets or sets the appointment date start.
        /// </summary>
        /// <value>
        /// The appointment date start.
        /// </value>
		public DateTime AppointmentDateStart {get{return this.dtpDateStart.Value;}set{this.dtpDateStart.Value=value;}}
		
		void BtnSaveClick(object sender, EventArgs e)
		{
			if (string.IsNullOrEmpty(txtTitle.Text))
			{
				lblValidation.Text="Chưa chọn tên khách hàng.";
			}
			else if (dtpDateStart.Value >= dtpDateEnd.Value)
			{
				lblValidation.Text="Giờ kết thúc phải lớn hơn giờ bắt đầu.";
			}
			else
			{
                if (cbxKhachHangVangLai.Checked)
                {
                    this.DialogResult = DialogResult.Retry;
                }
                else
                {
                    // //Moi them phan nay 28/10/13
                    if (MessageBox.Show("Bạn đã đặt lịch sân tất cả các ngày khách hàng yêu cầu và tính công nợ?", "Thông báo"
                        , MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.DialogResult = DialogResult.Retry;
                    }
                }
                this.Close();

                // //Hien tai chuong trinh la nhu vay
                //this.DialogResult = DialogResult.OK;
                //this.Close();
			}
		}
		
		void BtnCancelClick(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}
		
		void DtpDateStartValueChanged(object sender, EventArgs e)
		{
			if (dtpDateEnd.Value <= dtpDateStart.Value)
			{
				dtpDateEnd.Value = dtpDateStart.Value.AddMinutes(15);
			}
		}

        private void NewAppointment_Load(object sender, EventArgs e)
        {
            clsKhachHangBUS KhachHangBus = new clsKhachHangBUS();
            DataTable dtKhachHangCauLong = KhachHangBus.LayBangKhachHangCauLong();
            DataView dv = new DataView(dtKhachHangCauLong);
            //dv.RowFilter = "MaKhachHang = 'CLVLCT'";
            //DataTable dtTemp = dv.ToTable();
            //IDKhachHangVangLaiChuaThuTien = int.Parse(dtTemp.Rows[0][KhachHangId].ToString());
            //dv.RowFilter = string.Empty;
            //dv.RowFilter = "MaKhachHang = 'CLVLDT'";
            //dtTemp = dv.ToTable();
            //IDKhachHangVangLaiDaThuTien = int.Parse(dtTemp.Rows[0][KhachHangId].ToString());
            //dv.RowFilter = "MaKhachHang = 'CLVL' or MaKhachHang = 'VLCL'";
            //IDKhachHangVangLai = int.Parse(dv.ToTable().Rows[0]["KhachHangId"].ToString());

            //for (int i = dtKhachHangCauLong.Rows.Count-1; i>=0; i--)
            //{
            //    if (dtKhachHangCauLong.Rows[i]["MaKhachHang"].ToString().Contains("CLVL"))
            //    {
            //        dtKhachHangCauLong.Rows.RemoveAt(i);
            //    }
            //}
            cboKhachHangCauLong.DataSource = dtKhachHangCauLong;
            cboKhachHangCauLong.DisplayMember = "HoTen";
            cboKhachHangCauLong.ValueMember = "KhachHangId";
        }

        private void cboKhachHangCauLong_SelectionChangeCommitted(object sender, EventArgs e)
        {
            txtTitle.Text = ((DataRowView)cboKhachHangCauLong.SelectedItem).Row["HoTen"].ToString();
            KhachHangId = int.Parse(((DataRowView)cboKhachHangCauLong.SelectedItem).Row["KhachHangId"].ToString());
        }

        private void rbtKhachHangVangLaiChuaThu_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtKhachHangVangLaiChuaThu.Checked)
            {
                AppointmentTitle = "KH vãng lai (chưa thu)";
                MoTa = " (chưa thu)";
                //txtTitle.Text = "KH vãng lai (chưa thu)";
                //KhachHangId = IDKhachHangVangLaiChuaThuTien;
                KhachHangId = IDKhachHangVangLai;
            }
        }

        private void rbtKhachHangVangLaiDaThu_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtKhachHangVangLaiDaThu.Checked)
            {
                AppointmentTitle = "KH vãng lai (đã thu)";
                MoTa = " (đã thu)";
                //txtTitle.Text = "KH vãng lai (đã thu)";
                //KhachHangId = IDKhachHangVangLaiDaThuTien;
                KhachHangId = IDKhachHangVangLai;
            }
        }

        private void cbxKhachHangVangLai_CheckedChanged(object sender, EventArgs e)
        {
            if (cbxKhachHangVangLai.Checked)
            {
                pnlVangLai.Enabled = true;
                rbtKhachHangVangLaiChuaThu.Checked = true;
            }
            else
            {
                rbtKhachHangVangLaiDaThu.Checked = true;
                pnlVangLai.Enabled = false;
                txtTitle.Text = string.Empty;
            }
        }

	}
}
